/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */
package com.windea.study.kotlin.fxgl.sample.sandbox

import com.almasb.fxgl.app.*
import com.almasb.fxgl.dsl.*
import com.almasb.fxgl.texture.*
import javafx.geometry.*
import javafx.scene.paint.*
import java.util.*

/**
 * http://blog.studiominiboss.com/pixelart #21
 * 1.
 * 2.
 * 3.
 *
 * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com)
 */
class QuadSample : GameApplication() {
	
	private val originals = ArrayList<Texture>()
	private val textures = ArrayList<Texture>()
	private val textures2 = ArrayList<Texture>()
	
	private var j = 0
	
	override fun initSettings(settings: GameSettings) {
		settings.width = 800
		settings.height = 600
		settings.title = "QuadSample"
		settings.version = "0.1"
	}
	
	override fun initGame() {
		getGameScene().setBackgroundColor(Color.BLACK)
		
		val ship = texture("player2.png")
		
		val h = 7.0
		
		println(h)
		
		for(i in 0..9) {
			val quad = ship.subTexture(Rectangle2D(0.0, i * h, ship.image.width, h))
			quad.translateY = 100 + i * h
			
			originals.add(quad)
			
			textures.add(quad.copy())
			textures2.add(quad.toColor(Color.RED))
			
			getGameScene().addUINode(quad)
		}
	}
	
	override fun onUpdate(tpf: Double) {
		
		val t = originals[j]
		
		t.image = textures2[j].image
		
		if(j > 0) {
			originals[j - 1].image = textures[j - 1].image
		}
		
		j++
		
		if(j == 10) {
			j = 0
		}
	}
}

fun main(args: Array<String>) {
	GameApplication.launch(QuadSample::class.java, args)
}
